package org.codetranslators.common;

import java.util.Vector;

/**
 * This class is a wrapper class around a node. It contains the node object and adds additional functionality
 * of a dominator tree node.
 *
 * It conforms to the Decorator design pattern (also known as Wrapper pattern).
 * @author shreesha123
 *
 */

public class DominatorTreeNode extends TreeNode{

	private TreeNode node;        // The contained node
	private Node graphNode;       // The node in the graph corresponding to this tree node

	public DominatorTreeNode(TreeNode node, Node graphNode){
		this.node = node;
		this.graphNode = graphNode;
	}

	public Node getGraphNode(){
		return graphNode;
	}

	public void display(){
		System.out.print("Node: " + node.getName()+ " Children = ");
		int numNodes = children.size();
		for(int i = 0; i < numNodes; i++){
			DominatorTreeNode node = (DominatorTreeNode) children.elementAt(i);
			System.out.print(node.getName() + ", ");
		}
		System.out.println("");
		for(int j = 0; j < numNodes; j++){
			DominatorTreeNode node = (DominatorTreeNode) children.elementAt(j);
			node.display();
		}
	}

	@Override
	public void addChild(TreeNode node) {
		super.addChild(node);
	}

	public Vector<DominatorTreeNode> getDTNChildren() {
		Vector<DominatorTreeNode> childs = new Vector<DominatorTreeNode>();
		for (TreeNode node : (Vector<DominatorTreeNode>)children)
		{
			childs.add((DominatorTreeNode)(node));
		}
		return childs;
	}


}
